﻿@model CommonApp.Models.Client

@{
    ViewBag.Title = "Client";
    Layout = "~/Views/Clients/_ClientsLayout.cshtml";
}

@{
    var showUID = true;
    var uId = string.Empty;
    var saveAction = "NewClient";
    var saveLabel = "Create client";

    if (Model != null && Model.Id > 0)
    {
        uId = Model.Id.ToString();
        showUID = false;
        saveAction = "Edit";
        saveLabel = "Apply changes";
    }
}

<h2>Client @uId</h2>


@using (Html.BeginForm(saveAction, "Clients"))
{
    
    <div style="margin-bottom: 10px;">    
        <a href="/Clients/" class="button">Go back</a>

        <input type="submit" value="@saveLabel" />
        @{ 
    if (Model != null && Model.Id > 0)
    {
                <input type="submit" onclick="return HandleDelete(this)" value="Delete client" />
    }
        }
    </div>
    
    @Html.HiddenFor(m => m.Id)
    @Html.ValidationSummary(true)

    <table>
        <tr>
            <td>@Html.LabelFor(m => m.FirstName)</td>
            <td>@Html.TextBoxFor(m => m.FirstName)</td>
            <td>@Html.ValidationMessageFor(m => m.FirstName)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.LastName)</td>
            <td>@Html.TextBoxFor(m => m.LastName)</td>
            <td>@Html.ValidationMessageFor(m => m.LastName)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.PassportSeries)</td>
            <td>@Html.TextBoxFor(m => m.PassportSeries)</td>
            <td>@Html.ValidationMessageFor(m => m.PassportSeries)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.PassportNumber)</td>
            <td>@Html.TextBoxFor(m => m.PassportNumber)</td>
            <td>@Html.ValidationMessageFor(m => m.PassportNumber)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.DateOfBirth)</td>
            <td>@Html.TextBox("DateOfBirth", Model.DateOfBirth.HasValue? Model.DateOfBirth.Value.ToString("MM/dd/yyyy"):"")</td>
            <td>@Html.ValidationMessageFor(m => m.DateOfBirth)</td>
        </tr>
    </table>
    
    <script>
        $(function () {
            $("#DateOfBirth").datepicker();
        });
    </script>
    
    <div style="margin-top: 10px;">    
        <a href="/Clients/" class="button">Go back</a>

        <input type="submit" value="@saveLabel" />

        @{ 
    if (Model != null && Model.Id > 0)
    {
        <input type="submit" onclick="return HandleDelete(this)" value="Delete client" />
            
        <a href="/Clients/NewCard/@uId" class="button">New Card</a>
        <a href="/Transfers/Index/@uId" class="button">Operations</a>
    }
        }
       
    </div>
}

@section scriptClients {
    <script src="@Url.Content("~/Scripts/clientsClient.js")" type="text/javascript"></script>
}